package com.lineage.server;

import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class IdFactoryNpc {
  private static final Log _log = LogFactory.getLog(IdFactoryNpc.class);
  
  private static IdFactoryNpc _instance;
  
  private Object _monitor;
  
  private AtomicInteger _nextId;
  
  public static IdFactoryNpc get() {
    if (_instance == null)
      _instance = new IdFactoryNpc(); 
    return _instance;
  }
  
  public IdFactoryNpc() {
    try {
      this._monitor = new Object();
      this._nextId = new AtomicInteger(2000000000);
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public int nextId() {
    synchronized (this._monitor) {
      int andIncrement = this._nextId.getAndIncrement();
      return andIncrement;
    } 
  }
  
  public int maxId() {
    synchronized (this._monitor) {
      int value = this._nextId.get();
      return value;
    } 
  }
}
